package com.mjw.zstu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mjw.zstu.entity.Message;
import com.mjw.zstu.mapper.MessageMapper;
import com.mjw.zstu.resultDto.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MessageService {
    @Autowired
    MessageMapper messageMapper;
    public JsonResult inserts(Message message){
        messageMapper.insert(message);
        return new JsonResult(200,"操作成功",null);
    }
    public JsonResult getlist(Message message){
        QueryWrapper<Message> queryWrapper=new QueryWrapper<>(message);
       List l= messageMapper.selectList(queryWrapper);
     return new JsonResult(200,"操作成功",l);
    }
    public JsonResult read(Message message){
        QueryWrapper<Message> queryWrapper=new QueryWrapper<>(message);
        List<Message> l= messageMapper.selectList(queryWrapper);
        for(Message m: l){
            if(m.getIs_read()==0){
                m.setIs_read(1);
                messageMapper.updateById(m);
            }
        }
        return new JsonResult(200,"操作成功",null);
    }


}
